package com.general.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.general.template.mapper.PowerAdminMapper;
import com.general.template.vo.AdminVo;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.general.template.pojo.PowerAdmin;
import com.general.template.service.PowerAdminService;

/**
 * @Author: 杰哥
 * Date: 2021/2/15 16:28
 * @Description:
 **/

@Service
public class PowerAdminServiceImpl extends ServiceImpl<PowerAdminMapper, PowerAdmin> implements PowerAdminService {


    @Override
    public int updateAdmin(AdminVo admin) {
        PowerAdminMapper baseMapper = this.getBaseMapper();
        PowerAdmin powerAdmin = new PowerAdmin();
        powerAdmin.setName(admin.getName());
        powerAdmin.setHeaderUrl(admin.getHeaderUrl());
        return baseMapper.update(powerAdmin, new QueryWrapper<PowerAdmin>().eq("id", admin.getId())
                .eq("username", admin.getUsername()).eq("status", 0));
    }

    @Override
    public int updatePwd(AdminVo admin) {
        PowerAdminMapper baseMapper = this.getBaseMapper();
        PowerAdmin powerAdmin = new PowerAdmin();
        powerAdmin.setPassword(admin.getPassword());
        return baseMapper.update(powerAdmin, new QueryWrapper<PowerAdmin>().eq("id", admin.getId())
                .eq("username", admin.getUsername()).eq("password", admin.getOldPassword()).eq("status", 0));
    }
}

